<script type="text/javascript" language="javascript">
    (function($) {
        /*whatever jQuery stuff*/
        $(function(){
			$('#sync').click(function(){
				$('#processing').append('<div class="wrap"><h2>Computer Data Processing...<\/h2><\/div>');
				
			});
        });
    })(jQuery);	
</script>		
<div class="wrap">
 	<div id="icon-index" class="icon32"><br /></div><h2><?php echo ucwords(str_replace('_',' ',$this->uri->segment(1)));?> &raquo; <?php echo ucwords(str_replace('_',' ',$this->uri->segment(2)));?></h2>
</div>
<div id="wpbody-content">
    <div class="metabox-holder" id="dashboard-widgets">
            <div class="inside">
				<form action="" method="post">
					<input type="hidden" name="sync" id="sync" />
					<input type="submit" class="button-primary" value="<?php echo lang('button_sync');?>"/>
				</form>
				<?php if(isset($_POST) && !empty($_POST)):?>
					<h2>Computer Data Processing...</h2>
					<?php										
						/*#############oni_song#############*/
						echo '<strong><i>Syncing Table oni_song...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_song";					
						$this->db->query($SQL);
						echo 'Delete Table oni_song...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();						
						$SQL = "INSERT INTO you2play_2013.oni_song(song_id, media_type_id, genre_id, rate_score, is_publish, letters, create_date, update_date) SELECT t.song_id, CASE
						WHEN t.genre_id=99 THEN 1
						WHEN t.genre_id=100 THEN 2
						WHEN t.genre_id=101 THEN 3
						ELSE (SELECT CASE
						WHEN parent_id=99 THEN 1
						WHEN parent_id=100 THEN 2
						WHEN parent_id=101 THEN 3
						END as media_type_id
						FROM you2play_live.live_genre WHERE genre_id=t.genre_id LIMIT 1)
						END as media_type_id,
						CASE
						WHEN t.genre_id=99 THEN 0
						WHEN t.genre_id=100 THEN 0
						WHEN t.genre_id=101 THEN 0
						WHEN t.genre_id=26 THEN 1
						WHEN t.genre_id=27 THEN 2
						WHEN t.genre_id=28 THEN 8
						WHEN t.genre_id=29 THEN 14
						WHEN t.genre_id=31 THEN 16
						WHEN t.genre_id=32 THEN 19
						WHEN t.genre_id=33 THEN 25
						WHEN t.genre_id=36 THEN 13
						WHEN t.genre_id=37 THEN 15
						ELSE t.genre_id
						END as genre_id, t.song_rate_score,
						CASE WHEN t.publish=1 THEN '1' ELSE '0' END as publish, t.song_letters, t.song_lastupdate, t.song_lastupdate FROM you2play_live.live_song as t";
						$this->db->query($SQL);
						$SQL = "UPDATE oni_song as t SET t.create_date = (SELECT FROM_UNIXTIME(convert_date,'%Y-%m-%d %H:%i:%s') as create_date FROM you2play_live.live_song_file as j WHERE j.song_id=t.song_id)";
						$this->db->query($SQL);
						$SQL = "SELECT * FROM you2play_live.live_song_selection";
						$dataResult = $this->db->query($SQL)->result();;
						foreach($dataResult as $value):
							if($value->section == "play_song" && $value->type == "hot_on_chart"):
								$this->db->update('oni_song',array('is_show_hot_on_chart' => '1'),array('song_id' => $value->song_id));
							elseif($value->section == "song" && $value->type == "hurt_song_mood"):
								$this->db->update('oni_song',array('is_show_hurt_song_mood' => '1'),array('song_id' => $value->song_id));
							elseif($value->section == "song" && $value->type == "love_song_mood"):
								$this->db->update('oni_song',array('is_show_love_song_mood' => '1'),array('song_id' => $value->song_id));
							elseif($value->section == "main" && $value->type == "new_released"):
								$this->db->update('oni_song',array('is_show_new_released' => '1'),array('song_id' => $value->song_id));
							elseif($value->section == "main" && $value->type == "oldie"):
								$this->db->update('oni_song',array('is_show_oldie' => '1'),array('song_id' => $value->song_id));							elseif($value->section == "song" && $value->type == "ost_song_mood"):
								$this->db->update('oni_song',array('is_show_ost_song_mood' => '1'),array('song_id' => $value->song_id));					elseif($value->section == "genre" && $value->type == "play_song"):
								$this->db->update('oni_song',array('is_show_play_song' => '1'),array('song_id' => $value->song_id));						elseif($value->section == "main" && $value->type == "recommend"):
								$this->db->update('oni_song',array('is_show_recommend' => '1'),array('song_id' => $value->song_id));				
							endif;
						endforeach;
						echo 'oni_song done!!!<br />';
						/*#############oni_song_click_stat#############*/
						echo '<strong><i>Syncing Table oni_song_click_stat...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_song_click_stat";					
						$this->db->query($SQL);
						echo 'Delete Table oni_song_click_stat...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();						
						$SQL = "INSERT INTO you2play_2013.oni_song_click_stat(song_id, song_click_rate, song_click_embed, update_date) SELECT song_id, song_click_rate_count, song_embed_count, song_click_rate_date FROM you2play_live.live_song_click_rate WHERE song_click_rate_date > '2012-01-01' GROUP BY song_id,song_click_rate_date";
						$this->db->query($SQL);
						$SQL = "UPDATE you2play_2013.oni_song_click_stat as t INNER JOIN you2play_ee.exp_chart as j ON(DATE(j.`date`)=t.update_date AND j.type='song') SET t.song_click_views=j.views WHERE j.entry_id=t.song_id";
						$this->db->query($SQL);
						$SQL = "UPDATE you2play_2013.oni_song as t SET t.views=(SELECT (song_click_rate+song_embed_count) as views FROM you2play_live.live_song as j WHERE j.song_id=t.song_id)";
						$this->db->query($SQL);						
						echo 'oni_song_click_stat done!!!<br />';
						/*#############oni_song_info#############*/
						echo '<strong><i>Syncing Table oni_song_info...</i></strong><br />';
						$this->db->reconnect();						
						$SQL = "DELETE FROM oni_song_info";					
						$this->db->query($SQL);
						echo 'Delete Table oni_song_info...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();						
						$SQL = "INSERT INTO you2play_2013.oni_song_info(song_id, song_name, song_file_name, song_file_ext, song_description, song_lyrics, song_tag, song_embed) SELECT t.song_id, CONVERT(cast(convert(j.song_name using latin1) as binary) USING utf8) as song_name, k.convert_date,'mp3', CONVERT(cast(convert(song_desc using latin1) as binary) USING utf8) as song_desc, CONVERT(cast(convert(song_lyric using latin1) as binary) USING utf8) as song_lyric, CONVERT(cast(convert(song_tag using latin1) as binary) USING utf8) as song_tag, song_embed FROM you2play_live.live_song as t LEFT JOIN you2play_live.live_song_desc as j ON (j.song_id=t.song_id  AND j.language_id=1) LEFT JOIN you2play_live.live_song_file as k ON(k.song_id=t.song_id)";
						$this->db->query($SQL);	
						$dataResult = $this->db->get('oni_song_info')->result();
						foreach($dataResult as $value):
							$data = array(
								'song_name' => urldecode($value->song_name),
								'song_description' => preg_replace('/\.\.\/\.\.\/image\/song\/(.+?)\//','http://static.you2play.com/2013/assets/images/../uploads/song/images/original/$1.jpg',urldecode($value->song_description)),
								'song_lyrics' => urldecode($value->song_lyrics),
								'song_embed' => urldecode($value->song_embed),
								'song_tag' => urldecode($value->song_tag)
							);
							$this->db->update('oni_song_info',$data,array('song_id' => $value->song_id));
						endforeach;		
						echo 'oni_song_info done!!!<br />';
						/*#############oni_song_rating#############*/
						echo '<strong><i>Syncing Table oni_song_rating...</i></strong><br />';
						$this->db->reconnect();					
						$SQL = "DELETE FROM oni_song_rating";					
						$this->db->query($SQL);
						echo 'Delete Table oni_song_rating...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_song_rating(song_id, user_id, song_rating_score) SELECT song_id, user_id, song_rating_score FROM you2play_live.live_song_rating GROUP BY song_id,user_id";
						$this->db->query($SQL);	
						echo 'oni_song_rating done!!!<br />';
						/*#############oni_genre#############*/
						echo '<strong><i>Syncing Table oni_genre...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_genre";					
						$this->db->query($SQL);
						echo 'Delete Table oni_genre...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_genre (genre_id, genre_name, update_by) VALUES 
						(1,'Pop','system'), 
						(2,'Rock','system'), 
						(3,'Metal','system'), 
						(8,'Jazz','system'), 
						(13,'R&B','system'), 
						(14,'Dance','system'), 
						(15,'HipHop/Rap','system'), 
						(16,'Classical/Instrumental','system'), 
						(17,'Folk/Country','system'), 
						(19,'Soundtrack','system'), 
						(20,'Occasion','system'), 
						(21,'World Music','system'), 
						(22,'Retro','system'), 
						(23,'Raggae','system'), 
						(25,'Electronics','system'), 
						(30,'Blues/Country/Folk','system'), 
						(34,'Various Artist','system')";
						$this->db->query($SQL);					
						echo 'oni_genre done!!!<br />';
						/*#############oni_song_album#############*/
						echo '<strong><i>Syncing Table oni_song_album...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_song_album";					
						$this->db->query($SQL);
						echo 'Delete Table oni_song_album...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_song_album(song_id, album_id, is_default) SELECT song_id,album_id, CASE WHEN album_default=1 THEN '1' ELSE '0' END as is_default FROM you2play_live.live_album_song";
						$this->db->query($SQL);	
						echo 'oni_song_album done!!!<br />';
						/*#############oni_song_artist#############*/
						echo '<strong><i>Syncing Table oni_song_artist...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_song_artist";					
						$this->db->query($SQL);
						echo 'Delete Table oni_song_artist...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_song_artist(song_id, artist_id, is_default) SELECT song_id,artist_id, CASE WHEN artist_default=1 THEN '1' ELSE '0' END as is_default FROM you2play_live.live_artist_song";
						$this->db->query($SQL);	
						echo 'oni_song_artist done!!!<br />';
						/*#############oni_label#############*/
						echo '<strong><i>Syncing Table oni_label...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_label";					
						$this->db->query($SQL);
						echo 'Delete Table oni_label...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_label(label_id, label_name) SELECT loyalty_label_id,loyalty_label_name FROM you2play_live.live_loyalty_label";
						$this->db->query($SQL);
						$dataResult = $this->db->get_where('oni_label')->result();
						foreach($dataResult as $value):
							$data = array(
								'label_name' => urldecode($value->label_name)
							);
							$this->db->update('oni_label',$data,array('label_id' => $value->label_id));
						endforeach;						
						echo 'oni_label done!!!<br />';
						/*#############oni_artist#############*/
						echo '<strong><i>Syncing Table oni_artist...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_artist";					
						$this->db->query($SQL);
						echo 'Delete Table oni_artist...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_artist(artist_id, media_type_id, genre_id, label_id, rate_score, is_publish, create_date, update_date) SELECT t.artist_id, CASE
						WHEN t.artist_genre_id=99 THEN 1
						WHEN t.artist_genre_id=100 THEN 2
						WHEN t.artist_genre_id=101 THEN 3
						ELSE (SELECT CASE
						WHEN parent_id=99 THEN 1
						WHEN parent_id=100 THEN 2
						WHEN parent_id=101 THEN 3
						END as media_type_id
						FROM you2play_live.live_genre WHERE genre_id=t.artist_genre_id LIMIT 1)
						END as media_type_id,
						CASE
						WHEN t.artist_genre_id=99 THEN 0
						WHEN t.artist_genre_id=100 THEN 0
						WHEN t.artist_genre_id=101 THEN 0
						WHEN t.artist_genre_id=26 THEN 1
						WHEN t.artist_genre_id=27 THEN 2
						WHEN t.artist_genre_id=28 THEN 8
						WHEN t.artist_genre_id=29 THEN 14
						WHEN t.artist_genre_id=31 THEN 16
						WHEN t.artist_genre_id=32 THEN 19
						WHEN t.artist_genre_id=33 THEN 25
						WHEN t.artist_genre_id=36 THEN 13
						WHEN t.artist_genre_id=37 THEN 15						
						ELSE t.artist_genre_id
						END as genre_id, t.label_id, t.artist_rate_score,
						CASE WHEN t.community_publish=1 THEN '1' ELSE '0' END as publish, t.artist_lastupdate, t.artist_lastupdate FROM you2play_live.live_artist as t LEFT JOIN you2play_live.live_genre as j ON(j.genre_id=t.artist_genre_id)";
						$this->db->query($SQL);
						$SQL = "SELECT * FROM you2play_live.live_artist_selection";
						$dataResult = $this->db->query($SQL)->result();
						foreach($dataResult as $value):
							if($value->section == "artist" && $value->type == "recommend"):
								$this->db->update('oni_artist',array('is_show_recommend' => '1'),array('artist_id' => $value->artist_id));
							elseif($value->section == "genre" && $value->type == "new_released"):
								$this->db->update('oni_artist',array('is_show_genre' => '1'),array('artist_id' => $value->artist_id));
							elseif($value->section == "artist" && $value->type == "dream_ticket"):
								$this->db->update('oni_artist',array('is_show_dream_ticket' => '1'),array('artist_id' => $value->artist_id));
							elseif($value->section == "artist" && $value->type == "archanian"):
								$this->db->update('oni_artist',array('is_show_archanian' => '1'),array('artist_id' => $value->artist_id));
							endif;
						endforeach;						
						echo 'oni_artist done!!!<br />';
						/*#############oni_artist_info#############*/
						echo '<strong><i>Syncing Table oni_artist_info...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_artist_info";					
						$this->db->query($SQL);
						echo 'Delete Table oni_artist_info...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_artist_info(artist_id, artist_name, artist_desc, artist_short_desc, artist_other_desc, artist_tag) SELECT t.artist_id, CONVERT(cast(convert(j.artist_name using latin1) as binary) USING utf8) as artist_name, CONVERT(cast(convert(j.artist_desc using latin1) as binary) USING utf8) as artist_desc, CONVERT(cast(convert(j.artist_short_desc using latin1) as binary) USING utf8) as artist_short_desc, CONVERT(cast(convert(j.artist_other_desc using latin1) as binary) USING utf8) as artist_other_desc, artist_tag FROM you2play_live.live_artist as t LEFT JOIN you2play_live.live_artist_desc as j ON(t.artist_id=j.artist_id AND j.language_id=1)";
						$this->db->query($SQL);
						$dataResult = $this->db->get_where('oni_artist_info')->result();
						foreach($dataResult as $value):
							$data = array(
								'artist_name' => urldecode($value->artist_name),
								'artist_desc' => preg_replace('/\.\.\/\.\.\/image\/artist\/(.+?)\//','http://static.you2play.com/2013/assets/images/../uploads/artist/images/original/$1.jpg',urldecode($value->artist_desc)),
								'artist_short_desc' => urldecode($value->artist_short_desc),
								'artist_other_desc' => urldecode($value->artist_other_desc),
								'artist_tag' => urldecode($value->artist_tag),
							);
							$this->db->update('oni_artist_info',$data,array('artist_id' => $value->artist_id));
						endforeach;					
						echo 'oni_artist_info done!!!<br />';
						/*#############oni_artist_rating#############*/
						echo '<strong><i>Syncing Table oni_artist_rating...</i></strong><br />';
						$this->db->reconnect();					
						$SQL = "DELETE FROM oni_artist_rating";					
						$this->db->query($SQL);
						echo 'Delete Table oni_artist_rating...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_artist_rating(artist_id, user_id, artist_rating_score) SELECT artist_id, user_id, artist_rating_score FROM you2play_live.live_artist_rating GROUP BY artist_id,user_id";
						$this->db->query($SQL);	
						echo 'oni_artist_rating done!!!<br />';						
						/*#############oni_artist_image#############*/
						echo '<strong><i>Syncing Table oni_artist_image...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_artist_image";					
						$this->db->query($SQL);
						echo 'Delete Table oni_artist_image...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_artist_image(artist_image_id, artist_id, artist_image_group_id, artist_file_name, artist_file_ext, artist_image_category, artist_image_order) SELECT artist_img_id, artist_id, artist_img_group_id, artist_img_path, 'jpg',
						CASE
						WHEN artist_img_type='artist' THEN 'artist'
						WHEN artist_img_type='wallpaper' THEN 'wallpaper'
						WHEN artist_img_type='group' THEN 'group'
						ELSE 'uncategory'
						END as artist_image_category, artist_img_order FROM you2play_live.live_artist_image";
						$this->db->query($SQL);					
						echo 'oni_artist_image done!!!<br />';						
						/*#############oni_album#############*/
						echo '<strong><i>Syncing Table oni_album...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_album";					
						$this->db->query($SQL);
						echo 'Delete Table oni_album...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_album(album_id, label_id, album_price, is_publish) SELECT album_id, label_id, album_price,
						CASE
						WHEN publish=0 THEN '0'
						ELSE '1'
						END as publish FROM you2play_live.live_album";
						$this->db->query($SQL);
						$SQL = "SELECT * FROM you2play_live.live_album_selection";
						$dataResult = $this->db->query($SQL)->result();
						foreach($dataResult as $value):
							if($value->section == "main" && $value->type == "recommend"):
								$this->db->update('oni_album',array('is_show_recommend' => '1'),array('album_id' => $value->album_id));
							endif;
						endforeach;					
						echo 'oni_album done!!!<br />';
						/*#############oni_album_info#############*/
						echo '<strong><i>Syncing Table oni_album_info...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_album_info";					
						$this->db->query($SQL);
						echo 'Delete Table oni_album_info...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_album_info(album_id, album_name, album_file_name, album_file_ext, album_description, album_release_date, is_show_release_date, album_tag) SELECT t.album_id, CONVERT(cast(convert(t.album_name using latin1) as binary) USING utf8) as album_name, j.album_image_path, 'jpg', CONVERT(cast(convert(t.album_desc using latin1) as binary) USING utf8) as album_desc, album_release_date,
						CASE
						WHEN album_show_release_date=0 THEN '0'
						ELSE '1'
						END as album_show_release_date,
						CONVERT(cast(convert(j.album_tag using latin1) as binary) USING utf8) as album_tag FROM you2play_live.live_album_desc as t INNER JOIN you2play_live.live_album as j ON(j.album_id=t.album_id) WHERE t.language_id=1";
						$this->db->query($SQL);
						$dataResult = $this->db->get('oni_album_info')->result();
						foreach($dataResult as $value):
							$data = array(
								'album_name' => urldecode($value->album_name),
								'album_description' => preg_replace('/\.\.\/\.\.\/image\/album\/(.+?)\//','http://static.you2play.com/2013/assets/images/../uploads/album/images/original/$1.jpg',urldecode($value->album_description)),
								'album_tag' => urldecode($value->album_tag)
							);
							$this->db->update('oni_album_info',$data,array('album_id' => $value->album_id));
						endforeach;						
						echo 'oni_album_info done!!!<br />';
						/*#############oni_video#############*/
						echo '<strong><i>Syncing oni_video...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_video";					
						$this->db->query($SQL);
						echo 'Delete Table oni_video...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_video(video_id, video_type_id, media_type_id, genre_id, rate_score, is_publish, create_date, update_date) SELECT t.video_id, t.video_type_id,CASE
						WHEN t.genre_id=99 THEN 1
						WHEN t.genre_id=100 THEN 2
						WHEN t.genre_id=101 THEN 3
						ELSE (SELECT CASE
						WHEN parent_id=99 THEN 1
						WHEN parent_id=100 THEN 2
						WHEN parent_id=101 THEN 3
						END as media_type_id
						FROM you2play_live.live_genre WHERE genre_id=t.genre_id LIMIT 1)
						END as media_type_id,
						CASE
						WHEN t.genre_id=99 THEN 0
						WHEN t.genre_id=100 THEN 0
						WHEN t.genre_id=101 THEN 0
						WHEN t.genre_id=26 THEN 1
						WHEN t.genre_id=27 THEN 2
						WHEN t.genre_id=28 THEN 8
						WHEN t.genre_id=29 THEN 14
						WHEN t.genre_id=31 THEN 16
						WHEN t.genre_id=32 THEN 19
						WHEN t.genre_id=33 THEN 25
						WHEN t.genre_id=36 THEN 13
						WHEN t.genre_id=37 THEN 15						
						ELSE t.genre_id
						END as genre_id, t.video_rate_score,
						'1', t.video_lastupdate, t.video_lastupdate FROM you2play_live.live_video as t";
						$this->db->query($SQL);
						$SQL = "SELECT * FROM you2play_live.live_video_selection";
						$dataResult = $this->db->query($SQL)->result();;
						foreach($dataResult as $value):
							if($value->section == "main" && $value->type == "display_on_home"):
								$this->db->update('oni_video',array('is_show_display_on_home' => '1'),array('video_id' => $value->video_id));
							elseif($value->section == "hilight" && $value->type == "hilight_bhs"):
								$this->db->update('oni_video',array('is_show_hilight_bhs' => '1'),array('video_id' => $value->video_id));
							elseif($value->section == "hilight" && $value->type == "hilight_concert"):
								$this->db->update('oni_video',array('is_show_hilight_concert' => '1'),array('video_id' => $value->video_id));
							elseif($value->section == "hilight" && $value->type == "hilight_interview"):
								$this->db->update('oni_video',array('is_show_hilight_interview' => '1'),array('video_id' => $value->video_id));
							elseif($value->section == "hilight" && $value->type == "hilight_mv"):
								$this->db->update('oni_video',array('is_show_hilight_mv' => '1'),array('video_id' => $value->video_id));					elseif($value->section == "main" && $value->type == "new_released"):
								$this->db->update('oni_video',array('is_show_new_released' => '1'),array('video_id' => $value->video_id));			elseif($value->section == "main" && $value->type == "recommend"):
								$this->db->update('oni_video',array('is_show_recommend' => '1'),array('video_id' => $value->video_id));			elseif($value->section == "main" && $value->type == "video_hit"):
								$this->db->update('oni_video',array('is_show_video_hit' => '1'),array('video_id' => $value->video_id));				
							endif;
						endforeach;					
						echo 'oni_video done!!!<br />';
						/*#############oni_video_click_stat#############*/
						echo '<strong><i>Syncing oni_video_click_stat...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_video_click_stat";					
						$this->db->query($SQL);
						echo 'Delete Table oni_video_click_stat...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_video_click_stat(video_id, video_click_rate, video_click_embed, update_date) SELECT video_id, video_click_rate_count, video_embed_count, video_click_rate_date FROM you2play_live.live_video_click_rate WHERE video_click_rate_date > '2012-01-01' GROUP BY video_id,video_click_rate_date";
						$this->db->query($SQL);
						$SQL = "UPDATE you2play_2013.oni_video_click_stat as t INNER JOIN you2play_ee.exp_chart as j ON(DATE(j.`date`)=t.update_date AND j.type='video') SET t.video_click_views=j.views WHERE j.entry_id=t.video_id";
						$this->db->query($SQL);
						$SQL = "UPDATE you2play_2013.oni_video as t SET t.views=(SELECT (video_click_rate+video_embed_count) as views FROM you2play_live.live_video as j WHERE j.video_id=t.video_id)";
						$this->db->query($SQL);						
						echo 'oni_video_click_stat done!!!<br />';						
						/*#############oni_video_info#############*/
						echo '<strong><i>Syncing oni_video_info...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_video_info";					
						$this->db->query($SQL);
						echo 'Delete Table oni_video_info...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_video_info(video_id, video_name, video_thumb_name, video_thumb_ext, video_file_name, video_file_ext, video_description, video_embed, video_tag) SELECT t.video_id, CONVERT(cast(convert(j.video_name using latin1) as binary) USING utf8) as video_name, t.video_thumb,'jpg', k.video_path, 'mp4', CONVERT(cast(convert(j.video_desc using latin1) as binary) USING utf8) as video_desc, t.video_embed, CONVERT(cast(convert(t.video_tag using latin1) as binary) USING utf8) as video_tag FROM you2play_live.live_video as t LEFT JOIN you2play_live.live_video_desc as j ON (j.video_id=t.video_id  AND j.language_id=1) LEFT JOIN you2play_live.live_video_file as k ON (k.video_id=t.video_id) GROUP BY t.video_id";
						$this->db->query($SQL);
						$dataResult = $this->db->get('oni_video_info')->result();
						foreach($dataResult as $value):
							$data = array(
								'video_name' => urldecode($value->video_name),
								'video_description' => preg_replace('/\.\.\/\.\.\/image\/video\/(.+?)\//','http://static.you2play.com/2013/assets/images/../uploads/video/images/original/$1.jpg',urldecode($value->video_description)),
								'video_embed' => urldecode($value->video_embed),
								'video_tag' => urldecode($value->video_tag)
							);
							$this->db->update('oni_video_info',$data,array('video_id' => $value->video_id));
						endforeach;						
						echo 'oni_video_info done!!!<br />';
						/*#############oni_video_type#############*/
						echo '<strong><i>Syncing oni_video_type...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_video_type";					
						$this->db->query($SQL);
						echo 'Delete Table oni_video_type...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_video_type(video_type_id, video_type_name) SELECT video_type_id, video_type_name FROM you2play_live.live_video_type";
						$this->db->query($SQL);;						
						echo 'oni_video_type done!!!<br />';
						/*#############oni_video_song#############*/
						echo '<strong><i>Syncing Table oni_video_song...</i></strong><br />';
						$this->db->reconnect();						
						$SQL = "DELETE FROM oni_video_song";					
						$this->db->query($SQL);
						echo 'Delete Table oni_video_song...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_video_song(video_id, song_id) SELECT video_id, song_id FROM you2play_live.live_song_video";
						$this->db->query($SQL);	
						echo 'oni_video_song done!!!<br />';
						/*#############oni_video_artist#############*/
						echo '<strong><i>Syncing Table oni_video_artist...</i></strong><br />';
						$this->db->reconnect();						
						$SQL = "DELETE FROM oni_video_artist";					
						$this->db->query($SQL);
						echo 'Delete Table oni_video_artist...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_video_artist(video_id, artist_id) SELECT video_id, artist_id FROM you2play_live.live_artist_video";
						$this->db->query($SQL);	
						echo 'oni_video_artist done!!!<br />';																					/*#############oni_video_album#############*/
						echo '<strong><i>Syncing Table oni_video_album...</i></strong><br />';
						$this->db->reconnect();						
						$SQL = "DELETE FROM oni_video_album";					
						$this->db->query($SQL);
						echo 'Delete Table oni_video_album...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_video_album(video_id, album_id) SELECT video_id, album_id FROM you2play_live.live_album_video";
						$this->db->query($SQL);	
						echo 'oni_video_album done!!!<br />';		
						/*#############oni_artist_click_stat#############*/
						echo '<strong><i>Syncing oni_artist_click_stat...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_artist_click_stat";					
						$this->db->query($SQL);
						echo 'Delete Table oni_artist_click_stat...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_artist_click_stat(artist_id, artist_click_rate, update_date) SELECT artist_id, artist_click_rate_count, artist_click_rate_date FROM you2play_live.live_artist_click_rate WHERE artist_click_rate_date > '2012-01-01' GROUP BY artist_id,artist_click_rate_date";
						$this->db->query($SQL);
						$SQL = "UPDATE you2play_2013.oni_artist_click_stat as t INNER JOIN you2play_ee.exp_chart as j ON(DATE(j.`date`)=t.update_date AND j.type='artist') INNER JOIN you2play_live.live_artist as k ON(k.artist_sef=j.name) SET t.artist_click_views=j.views WHERE t.artist_id=k.artist_id";
						$this->db->query($SQL);
						$SQL = "UPDATE oni_artist as t SET t.views=(SELECT SUM(artist_click_views) as views FROM `oni_artist_click_stat` as j  WHERE j.artist_id=t.artist_id GROUP BY j.artist_id)";
						$this->db->query($SQL);						
						echo 'oni_artist_click_stat done!!!<br />';	
						/*#############oni_news_type#############*/
						echo '<strong><i>Syncing oni_news_type...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_news_type";
						$this->db->query($SQL);
						echo 'Delete Table oni_news_type...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_news_type (news_type_id, news_type_name, update_by) VALUES (1,'Thai','system'), (2,'Inter','system'), (3,'Asian','system'), (4,'P.R.','system'), (5,'Album Review','system'), (6,'Movie','system'), (7,'Article','system')";
						$this->db->query($SQL);
						echo 'oni_news_type done!!!<br />';						
						/*#############oni_news#############*/
						echo '<strong><i>Syncing oni_news...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_news WHERE news_id < 20000";
						$this->db->query($SQL);
						echo 'Delete Table oni_news...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_news(news_id, news_type_id, news_publish_date, is_publish, create_date, update_date) 
						SELECT t.news_id, 
						CASE 
							WHEN t.news_categories='news' THEN 1
						 	WHEN t.news_categories='event' THEN 1
						 	WHEN t.news_categories='webmaster' THEN 1
						 	WHEN t.news_categories='archanian' THEN 1
						 	WHEN t.news_categories='news_tv' THEN 1
						 	WHEN t.news_categories='hilight_tv' THEN 1
						 	WHEN t.news_categories='programe_tv' THEN 1
						END as news_type_id,
						t.news_publish_date,
						CASE
							WHEN t.news_publish=1 THEN '1'
							ELSE '0'
						END as is_publish,		
						t.news_lastupdate,t.news_lastupdate FROM you2play_live.live_news as t LEFT JOIN you2play_live.live_news_selection as j ON(j.news_id=t.news_id)";
						$this->db->query($SQL);										
						echo 'oni_news done!!!<br />';						
						/*#############oni_news_info#############*/
						echo '<strong><i>Syncing oni_news_info...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_news_info WHERE news_id < 20000";					
						$this->db->query($SQL);
						echo 'Delete Table oni_news_info...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_news_info(news_id, news_subject,news_brief,news_detail,news_tag) 
						SELECT t.news_id,CONVERT(cast(convert(t.news_head using latin1) as binary) USING utf8) as news_subject,CONVERT(cast(convert(t.news_short_desc using latin1) as binary) USING utf8) as news_brief,CONVERT(cast(convert(t.news_content using latin1) as binary) USING utf8) as news_detail,CONVERT(cast(convert(t.news_tag using latin1) as binary) USING utf8) as news_tag FROM you2play_live.live_news as t";
						$this->db->query($SQL);
						$dataResult = $this->db->get_where('oni_news_info',array('news_id <' => 20000))->result();
						foreach($dataResult as $value):
							$data = array(
								'news_subject'	=> urldecode($value->news_subject),
								'news_brief'	=> urldecode($value->news_brief),
								'news_detail'	=> preg_replace('/\.\.\/\.\.\/image\/news\/(.+?)\//','http://static.you2play.com/2013/assets/images/../uploads/news/images/original/$1.jpg',urldecode($value->news_detail)),
								'news_tag'		=> urldecode($value->news_tag)
							);
						$this->db->update('oni_news_info',$data,array('news_id'=> $value->news_id));
						endforeach;					
						echo 'oni_news_info done!!!<br />';
						/*#############oni_news_artist#############*/
						echo '<strong><i>Syncing oni_news_artist...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_news_artist WHERE news_id < 20000";					
						$this->db->query($SQL);
						echo 'Delete Table oni_news_artist...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_news_artist(news_id, artist_id) 
						SELECT news_id,artist_id FROM you2play_live.live_artist_news";
						$this->db->query($SQL);				
						echo 'oni_news_artist done!!!<br />';
						/*#############oni_news_image#############*/
						echo '<strong><i>Syncing Table oni_news_image...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_news_image WHERE news_id < 20000";					
						$this->db->query($SQL);
						echo 'Delete Table oni_news_image...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_news_image(news_id, news_file_name, news_file_ext, news_image_order) 
						SELECT news_id,news_image_path,'jpg',news_image_order FROM you2play_live.live_news_image";
						$this->db->query($SQL);			
						echo 'oni_news_image done!!!<br />';
						/*#############oni_movie_type#############*/
						echo '<strong><i>Syncing oni_movie_type...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_movie_type";
						$this->db->query($SQL);
						echo 'Delete Table oni_movie_type...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_movie_type (movie_type_id, movie_type_name, update_by) VALUES (1,'Action','system'), (2,'Adventure','system'), (3,'Animation','system'), (4,'Biography','system'), (5,'Comedy','system'), (6,'Crime','system'), (7,'Documentar','system'), (8,'Drama','system'),(9,'Erotic','system'), (10,'Fantasy','system'), (11,'Horror','system'), (12,'Music','system'), (13,'Romantic','system'), (14,'Sci-Fi','system'), (15,'Thriller','system'), (16,'War','system')";
						$this->db->query($SQL);
						echo 'oni_movie_type done!!!<br />';
						/*#############oni_movie_type_relate#############*/
						echo '<strong><i>Syncing oni_movie_type_relate...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_movie_type_relate";
						$this->db->query($SQL);
						echo 'Delete Table oni_movie_type_relate...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_movie_type_relate (movie_id, movie_type_id) SELECT entry_id,CASE
						WHEN cat_id=11 THEN 1
						WHEN cat_id=18 THEN 2
						WHEN cat_id=15 THEN 3
						WHEN cat_id=88 THEN 4
						WHEN cat_id=5 THEN 5
						WHEN cat_id=89 THEN 6
						WHEN cat_id=14 THEN 7
						WHEN cat_id=3 THEN 8
						WHEN cat_id=81 THEN 9
						WHEN cat_id=17 THEN 10
						WHEN cat_id=12 THEN 11
						WHEN cat_id=91 THEN 12
						WHEN cat_id=16 THEN 13
						WHEN cat_id=14 THEN 14
						WHEN cat_id=13 THEN 15
						WHEN cat_id=90 THEN 16
						END as movie_type_id FROM you2play_ee.exp_category_posts WHERE cat_id IN (11,18,15,88,5,89,14,3,81,17,12,91,16,4,13,90)";
						$this->db->query($SQL);
						echo 'oni_movie_type_relate done!!!<br />';
						/*#############oni_movie#############*/
						echo '<strong><i>Syncing oni_movie...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_movie";
						$this->db->query($SQL);
						echo 'Delete Table oni_movie...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_movie (movie_id,views,is_publish,is_video_clip,create_date,update_date) SELECT entry_id,view_count_one,CASE WHEN status='open' THEN '1' ELSE '0' END as is_publish,CASE WHEN channel_id=1 THEN '0' ELSE '1' END as is_video_clip,FROM_UNIXTIME(entry_date,'%Y-%m-%d %H:%i:%s') as create_date,CONCAT(SUBSTR(edit_date,1,4),'-',SUBSTR(edit_date,5,2),'-',SUBSTR(edit_date,7,2),' ',SUBSTR(edit_date,9,2),':',SUBSTR(edit_date,11,2),':',SUBSTR(edit_date,13,2)) as update_date FROM you2play_ee.exp_channel_titles WHERE channel_id IN (1,2)";
						$this->db->query($SQL);
						$SQL = "UPDATE you2play_2013.oni_movie as t INNER JOIN you2play_ee.exp_category_posts as j ON (j.entry_id=t.movie_id AND j.cat_id < 3) SET t.media_type_id=(CASE 
						WHEN j.cat_id=1 THEN 2 ELSE 1 END)";
						$this->db->query($SQL);	
						echo 'oni_movie done!!!<br />';
						/*#############oni_movie_info#############*/
						echo '<strong><i>Syncing oni_movie_info...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_movie_info";
						$this->db->query($SQL);
						echo 'Delete Table oni_movie_info...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_movie_info (movie_id,movie_name,movie_description,movie_tag,movie_author,movie_actor,movie_file_name1,movie_file_ext1,movie_file_name2,movie_file_ext2,movie_file_name3,movie_file_ext3,movie_publish_date) SELECT t.entry_id,t.title,CASE WHEN t.channel_id=1 THEN j.field_id_1 ELSE j.field_id_15 END,CASE WHEN t.channel_id=1 THEN j.field_id_3 ELSE j.field_id_18 END,j.field_id_7,j.field_id_8,CASE WHEN t.channel_id=1 THEN j.field_id_10 ELSE j.field_id_16 END,'mp4',j.field_id_11,'mp4',j.field_id_13,'mp4',FROM_UNIXTIME(j.field_id_12,'%Y-%m-%d %H:%i:%s') as publish_date FROM you2play_ee.exp_channel_titles as t INNER JOIN you2play_ee.exp_channel_data as j ON (t.entry_id=j.entry_id) WHERE t.channel_id IN (1,2)";
						$this->db->query($SQL);
						echo 'oni_movie_info done!!!<br />';
						/*#############oni_movie_image#############*/
						echo '<strong><i>Syncing Table oni_movie_image...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_movie_image";					
						$this->db->query($SQL);
						echo 'Delete Table oni_movie_image...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_movie_image(movie_id, movie_file_name, movie_file_ext, movie_image_order) 
						SELECT t.entry_id as movie_id,CONCAT(CONCAT(t.entry_id,'_'),j.image_name) as movie_file_name,j.ext as movie_file_ext,j.image_order as movie_image_order FROM you2play_ee.exp_channel_titles as t INNER JOIN you2play_ee.exp_entry_gallery_files as j ON (j.entry_id=t.entry_id) WHERE t.channel_id IN(1,2)";
						$this->db->query($SQL);			
						echo 'oni_movie_image done!!!<br />';
						/*#############oni_gallery#############*/
						echo '<strong><i>Syncing Table oni_gallery...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_gallery";					
						$this->db->query($SQL);
						echo 'Delete Table oni_gallery...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_gallery (gallery_id,gallery_category,gallery_name,gallery_description,views,is_publish,create_date,update_date) SELECT gallery_id,CASE 
WHEN gallery_categories = '1' THEN 'Good FM Gallery' 
WHEN gallery_categories = '2' THEN 'Concert' 
WHEN gallery_categories = '3' THEN 'Press Conferrence' 
WHEN gallery_categories = '4' THEN 'Behind the scenes' 
WHEN gallery_categories = '5' THEN 'Artist' 
WHEN gallery_categories = '6' THEN 'Other' 
WHEN gallery_categories = '7' THEN 'Street fashion' 
END as gallery_category,gallery_name,gallery_desc,gallery_view_count,CASE WHEN publish=1 THEN '1' ELSE '0' END as is_publish,gallery_date,gallery_date FROM you2play_live.live_gallery";
						$this->db->query($SQL);
						$dataResult = $this->db->get('oni_gallery')->result();
						foreach($dataResult as $value):
							$data = array(
								'gallery_name'	=> urldecode($value->gallery_name),
								'gallery_description'	=> urldecode($value->gallery_description)
							);
						$this->db->update('oni_gallery',$data,array('gallery_id'=> $value->gallery_id));
						endforeach;											
						echo 'oni_gallery done!!!<br />';	
						/*#############oni_gallery_image#############*/
						echo '<strong><i>Syncing Table oni_gallery_image...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_gallery_image";					
						$this->db->query($SQL);
						echo 'Delete Table oni_gallery_image...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_gallery_image(gallery_id, gallery_file_name, gallery_file_ext, gallery_image_order) 
						SELECT gallery_id,gallery_image_file,'jpg',gallery_image_sequence FROM you2play_live.live_gallery_image";
						$this->db->query($SQL);			
						echo 'oni_gallery_image done!!!<br />';
						/*#############oni_gallery_click_stat#############*/
						echo '<strong><i>Syncing Table oni_gallery_click_stat...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_gallery_click_stat";					
						$this->db->query($SQL);
						echo 'Delete Table oni_gallery_click_stat...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();						
						$SQL = "INSERT INTO you2play_2013.oni_gallery_click_stat (gallery_id,gallery_click_rate,update_date) SELECT gallery_id,gallery_click_rate_count,gallery_click_rate_date FROM you2play_live.live_gallery_click_rate WHERE gallery_click_rate_date > '2012-01-01' AND gallery_id!=0 GROUP BY gallery_click_rate_date,gallery_id";
						$this->db->query($SQL);						
						echo 'oni_gallery_click_stat done!!!<br />';
						/*#############oni_calendar#############*/
						echo '<strong><i>Syncing oni_calendar...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_calendar";
						$this->db->query($SQL);
						echo 'Delete Table oni_calendar...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_calendar (calendar_id,calendar_activity_date_start,calendar_activity_date_end,is_publish) SELECT agenda_id,start_date,concat(DATE(end_date),' 23:59:59'),CASE WHEN status=1 THEN '1' ELSE '0' END FROM you2play_live.live_calendar_agenda";
						$this->db->query($SQL);
						echo 'oni_calendar done!!!<br />';
						/*#############oni_calendar_info#############*/
						echo '<strong><i>Syncing oni_calendar_info...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_calendar_info";
						$this->db->query($SQL);
						echo 'Delete Table oni_calendar_info...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_calendar_info (calendar_id,calendar_subject,calendar_brief,calendar_detail,calendar_place,calendar_link) SELECT agenda_id,title,short_detail,detail,place,link FROM you2play_live.live_calendar_agenda";
						$this->db->query($SQL);
						$dataResult = $this->db->get('oni_calendar_info')->result();
						foreach($dataResult as $value):
							$data = array(
								'calendar_subject'	=> urldecode($value->calendar_subject),
								'calendar_brief'	=> urldecode($value->calendar_brief),
								'calendar_detail'	=> urldecode($value->calendar_detail),
								'calendar_place'	=> urldecode($value->calendar_place),
								'calendar_link'	=> urldecode($value->calendar_link)
							);
							$this->db->update('oni_calendar_info',$data,array('calendar_id'=> $value->calendar_id));
						endforeach;
						echo 'oni_calendar_info done!!!<br />';
						echo 'oni_calendar_info done!!!<br />';
						/*#############oni_calendar_image#############*/
						echo '<strong><i>Syncing oni_calendar_image...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_calendar_image";
						$this->db->query($SQL);
						echo 'Delete Table oni_calendar_image...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_calendar_image (calendar_id,calendar_file_name,calendar_file_ext) SELECT agenda_id,photo,'jpg' FROM you2play_live.live_calendar_agenda WHERE photo != ''";
						$this->db->query($SQL);
						echo 'oni_calendar_image done!!!<br />';
						/*#############oni_fashion#############*/
						echo '<strong><i>Syncing Table oni_fashion...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_fashion";					
						$this->db->query($SQL);
						echo 'Delete Table oni_fashion...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_fashion (fashion_id,fashion_name,fashion_description,views,is_publish,create_date,update_date) SELECT t.entry_id,t.title,j.field_id_110,t.view_count_one,CASE WHEN t.status='open' THEN '1' ELSE '0' END as is_publish,FROM_UNIXTIME(t.entry_date),FROM_UNIXTIME(t.entry_date) FROM you2play_ee.exp_channel_titles as t INNER JOIN you2play_ee.exp_channel_data as j ON(j.entry_id=t.entry_id) WHERE t.channel_id = 17";
						$this->db->query($SQL);	 
						$SQL = "UPDATE you2play_2013.oni_fashion as t INNER JOIN you2play_ee.exp_category_posts as j ON(j.entry_id=t.fashion_id AND j.cat_id NOT IN(103,104,142)) SET t.fashion_category = CASE 
						WHEN j.cat_id = 100 THEN 'Fashion Magazine'
						WHEN j.cat_id = 101 THEN 'Fashion Women'
						WHEN j.cat_id = 102 THEN 'Fashion Men'
						WHEN j.cat_id = 107 THEN 'Event'
						END";
						$this->db->query($SQL);	
						$SQL = "UPDATE you2play_2013.oni_fashion as t INNER JOIN you2play_ee.exp_category_posts as j ON(j.entry_id=t.fashion_id AND j.cat_id NOT IN(100,101,102,107)) SET t.is_main_hilight = CASE
						WHEN j.cat_id = 103 THEN '1' ELSE '0'
						END";
						$this->db->query($SQL);										
						echo 'oni_fashion done!!!<br />';	
						/*#############oni_fashion_image#############*/
						echo '<strong><i>Syncing Table oni_fashion_image...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_fashion_image";					
						$this->db->query($SQL);
						echo 'Delete Table oni_fashion_image...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_fashion_image(fashion_id, fashion_file_name, fashion_file_ext, fashion_image_order) 
						SELECT t.entry_id,t.image_key,'jpg',t.image_order FROM you2play_ee.exp_entry_gallery_files as t INNER JOIN you2play_ee.exp_channel_titles as j ON(j.entry_id=t.entry_id) WHERE j.channel_id=17";
						$this->db->query($SQL);		
						$SQL = "SELECT t.entry_id,j.image_name as old_name,j.image_key as fashion_file_name,j.ext as fashion_file_ext,j.image_order as fashion_image_order FROM you2play_ee.exp_channel_titles as t INNER JOIN you2play_ee.exp_entry_gallery_files as j ON (j.entry_id=t.entry_id) WHERE t.channel_id = 17 AND j.ext NOT REGEXP BINARY '^jpg' ORDER BY t.entry_id ASC";
						$dataResult = $this->db->query($SQL)->result();
						$upload_path = '/home/you2play/engine/static/2013/assets/uploads/';
						foreach($dataResult as $key => $value):
							@rename($upload_path.'fashion/images/original/'.$value->fashion_file_name.'.'.$value->fashion_file_ext,$upload_path.'fashion/images/original/'.$value->fashion_file_name.'.jpg');	
							@rename($upload_path.'fashion/images/120x120/'.$value->fashion_file_name.'.'.$value->fashion_file_ext,$upload_path.'fashion/images/original/'.$value->fashion_file_name.'.jpg');	
						endforeach;							
						echo 'oni_fashion_image done!!!<br />';		
						/*#############oni_activity#############*/
						echo '<strong><i>Syncing Table oni_activity...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_activity";					
						$this->db->query($SQL);
						echo 'Delete Table oni_activity...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_activity(activity_id, is_publish, create_date, update_date) 
						SELECT t.entry_id as activity_id, '1', FROM_UNIXTIME(t.entry_date) as create_date,FROM_UNIXTIME(t.entry_date) as update_date  FROM you2play_ee.exp_channel_titles as t INNER JOIN you2play_ee.exp_channel_data as j ON (j.entry_id=t.entry_id) WHERE t.channel_id = 15";
						$this->db->query($SQL);						
						echo 'oni_activity done!!!<br />';
						/*#############oni_activity_info#############*/
						echo '<strong><i>Syncing Table oni_activity_info...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_activity_info";					
						$this->db->query($SQL);
						echo 'Delete Table oni_activity_info...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_activity_info(activity_id, activity_subject, activity_brief, activity_detail) 
						SELECT t.entry_id as activity_id,t.title as activity_subject,j.field_id_103 as activity_brief,j.field_id_101 as activity_detail FROM you2play_ee.exp_channel_titles as t INNER JOIN you2play_ee.exp_channel_data as j ON (j.entry_id=t.entry_id) WHERE t.channel_id = 15";
						$this->db->query($SQL);						
						echo 'oni_activity_info done!!!<br />';		
						/*#############oni_activity_image#############*/
						echo '<strong><i>Syncing Table oni_activity_image...</i></strong><br />';
						$this->db->reconnect();
						$SQL = "DELETE FROM oni_activity_image";					
						$this->db->query($SQL);
						echo 'Delete Table oni_activity_image...<br />';
						// now flush output output to client
						@ob_end_flush();
						flush();
						$SQL = "INSERT INTO you2play_2013.oni_activity_image(activity_id, activity_file_name, activity_file_ext) 
						SELECT t.entry_id as activity_id, SUBSTRING(REPLACE(j.field_id_92,'{filedir_7}',''),1,LENGTH(REPLACE(j.field_id_92,'{filedir_7}',''))-4) as activity_file_name,SUBSTRING(j.field_id_92,-3) as activity_file_ext FROM you2play_ee.exp_channel_titles as t INNER JOIN you2play_ee.exp_channel_data as j ON (j.entry_id=t.entry_id) WHERE t.channel_id = 15";
						$this->db->query($SQL);						
						echo 'oni_activity_image done!!!<br />';																			
						echo '<h2>Congratulation!!! Sync all data is complete.. :)</h2>';
						echo '<h2>*It may use several time to complete all process..</h2>';
					?>
				<?php endif;?>
            </div><!-- wpbody inside -->
    </div><!-- wpcontent -->
</div><!-- wpbody-content -->